{% extends 'base.html' %}

{% block title %}{% if group %}编辑用户组{% else %}新增用户组{% endif %} - 固定资产管理系统{% endblock %}

{% block content %}
<div class="row">
    <div class="col-md-8">
        <h2>{% if group %}编辑用户组{% else %}新增用户组{% endif %}</h2>
        
        <form method="post">
            {% csrf_token %}
            
            <div class="mb-3">
                <label for="name" class="form-label">用户组名称 *</label>
                <input type="text" class="form-control" id="name" name="name" value="{% if group %}{{ group.name }}{% else %}{{ name|default:'' }}{% endif %}" required>
            </div>
            
            <div class="mb-3">
                <label for="permissions" class="form-label">权限</label>
                <select multiple class="form-select" id="permissions" name="permissions" size="15">
                    {% for permission in permissions %}
                        <option value="{{ permission.id }}" {% if group and permission in group.permissions.all or permission.id|stringformat:"i" in permission_ids %}selected{% endif %}>
                            {{ permission.content_type.app_label }}.{{ permission.content_type }}: {{ permission.name }}
                        </option>
                    {% endfor %}
                </select>
                <div class="form-text">按住 Ctrl 键可多选</div>
            </div>
            
            <div class="mb-3">
                <button type="submit" class="btn btn-primary">{% if group %}更新{% else %}创建{% endif %}</button>
                <a href="{% url 'assets:group_list' %}" class="btn btn-secondary">取消</a>
            </div>
        </form>
    </div>
</div>
{% endblock %}